﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;

public partial class Admin_AdminProductsMacAddNew : System.Web.UI.Page
{
    string connectionString;
    private SqlConnection con;
    private SqlDataAdapter da;
    private SqlCommand cmd;
    private DataSet ds;
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString = WebConfigurationManager.ConnectionStrings["AppleShopConnectionString"].ToString();
        con = new SqlConnection(connectionString);
        con.Open();
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        try
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }


            con.Open();

            cmd = new SqlCommand("spGetAddNewMac", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@ProductsID", SqlDbType.VarChar).Value = txtID.Text;
            cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txtName.Text;
            cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value = dropDownTypeProduct.Text;
            cmd.Parameters.Add("@Price", SqlDbType.Float).Value = float.Parse(txtPrice.Text);
            string img = FileUpload1.FileName.ToString();
            cmd.Parameters.Add("@Image", SqlDbType.VarChar).Value = "~\\IMG\\mac\\" + img;
            cmd.ExecuteNonQuery();
            //upload image on server

            FileUpload1.SaveAs(Server.MapPath("~\\IMG\\mac\\" + img));
            Response.Redirect("AdminProductsMac.aspx");
        }

        catch (SqlException ex)
        {
            throw new Exception(ex.Message);
        }

        finally
        {
            con.Close();
        }
    }
    protected void btnNewDetails_Click(object sender, EventArgs e)
    {
        try
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }


            con.Open();

            cmd = new SqlCommand("spGetInsertDetails", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@DetailsID", SqlDbType.VarChar).Value = DropDownList2.Text;
            cmd.Parameters.Add("@DetailsText", SqlDbType.VarChar).Value = txtDetails.Text;
            string imgs = FileUpload2.FileName.ToString();
            cmd.Parameters.Add("@DetailsImage", SqlDbType.VarChar).Value = "~\\IMG\\iPod\\" + imgs;
            cmd.ExecuteNonQuery();
            //upload image on server

            FileUpload2.SaveAs(Server.MapPath("~\\IMG\\iPod\\" + imgs));
            Response.Redirect("AdminProductsMac.aspx");
        }

        catch (SqlException ex)
        {
            throw new Exception(ex.Message);
        }

        finally
        {
            con.Close();
        }
    }
}